package com.huika.renrench.db.areainfo;

import java.util.List;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.huika.renrench.GlobalApp;
import com.huika.renrench.db.areainfo.AreaInfoDao.Properties;
import com.huika.renrench.support.bean.AreaInfo;

public class AreaInfoDbHelper {
	
	private AreaInfoDaoSession mAreaInfoDaoSession;  
    private AreaInfoDao mAreaInfoDao;  
	private SQLiteDatabase db;
	private Context mContext;
    public AreaInfoDbHelper() {  
    	AreaInfoDaoMaster daoMaster = GlobalApp.getAreaInfoDaoMaster();
    	mAreaInfoDaoSession=daoMaster.newSession(); 
    	mAreaInfoDao = mAreaInfoDaoSession.getAreaInfoDao();
		db = daoMaster.getDatabase();
    }
    
    public AreaInfoDbHelper(Context mContext) {  
    	this();
    	this.mContext=mContext;
    }
    
	public long getTotalCount(){
		return mAreaInfoDao.queryBuilder().count();
	}
	
	public List<AreaInfo> getProvinceList() {
		return mAreaInfoDao.queryBuilder().where(Properties.ParentID.eq(1)).orderAsc(Properties.AreaID).list();
	}
	

	public List<AreaInfo> getAreaListByParentID(int parentID) {
		return mAreaInfoDao.queryBuilder().where(Properties.ParentID.eq(parentID)).orderAsc(Properties.AreaID).list();
	}
	
	public int getAreaIDByName2(String Name) {
		
		List<AreaInfo> list = mAreaInfoDao.queryBuilder().where(Properties.AreaName.like(Name)).orderAsc(Properties.AreaID).list();
		if (list.size() > 0) {
			return list.get(0).getAreaId();
		}
		return -1;
	}
	
	public int getAreaIDByNamePath(String namePath) {
		List<AreaInfo> list = mAreaInfoDao.queryBuilder().where(Properties.NamePath.like("%" + namePath + "%")).orderAsc(Properties.AreaID).list();
		if (list.size() > 0) {
			return list.get(0).getAreaId();
		}
		return -1;
	}
	
}
